/**
 * Copyright [2019] [LiBo/Alex of copyright liboware@gmail.com ]
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.dess.mybatis.plugins.client;

import com.google.common.collect.Maps;
import com.hyts.dess.mybatis.plugins.bean.Sample;
import com.hyts.dess.mybatis.plugins.execute.CustomExecutorConstant;
import lombok.Getter;

import java.util.Map;

/**
 * @project-name:mybatis-demo
 * @package-name:com.znlh.demo.mybatisdemo.client
 * @author:LiBo/Alex
 * @create-date:2020-06-16 13:07
 * @copyright:libo-alex4java
 * @email:liboware@gmail.com
 * @description: 本地客户端操作处理
 */
public class MyLocalClient {

    /**
     * 数据存储内存
     */
    @Getter
    private static final Map<String,Object> dataMemory = Maps.newConcurrentMap();

    @Getter
    private static final Map<String,Object> localMemory = Maps.newConcurrentMap();

    @Getter
    private static final Map<String,Object> remoteMemory = Maps.newConcurrentMap();

    /**
     * 静态参数操作处理
     */
    static{
        dataMemory.put(CustomExecutorConstant.DEFAULT_EXECUTOR_CONDITION_KEY,"userName");
        dataMemory.put(CustomExecutorConstant.DEFAULT_EXECUTOR_CONDITION_TOKEN,"=");
        dataMemory.put(CustomExecutorConstant.DEFAULT_EXECUTOR_CALLER_TYPE,"local");
        dataMemory.put(CustomExecutorConstant.DEFAULT_EXECUTOR_CONDITION_VALUE,"@[root.value]");
        dataMemory.put(CustomExecutorConstant.DEFAULT_EXECUTOR_CONTEXT_SUBJECT,new Sample("1","2"));

        localMemory.put(CustomExecutorConstant.DEFAULT_EXECUTOR_CONDITION_KEY,"userName");
        localMemory.put(CustomExecutorConstant.DEFAULT_EXECUTOR_CONDITION_TOKEN,"=");
        localMemory.put(CustomExecutorConstant.DEFAULT_EXECUTOR_CALLER_TYPE,"local");
        localMemory.put(CustomExecutorConstant.DEFAULT_EXECUTOR_CONDITION_VALUE,
                "#[com.znlh.demo.mybatisdemo.client.MyLocalClient.imitateDataFromMemory(root.key,root.value)]");
        localMemory.put(CustomExecutorConstant.DEFAULT_EXECUTOR_CONTEXT_SUBJECT,new Sample("1","2"));

        remoteMemory.put(CustomExecutorConstant.DEFAULT_EXECUTOR_CONDITION_KEY,"userName");
        remoteMemory.put(CustomExecutorConstant.DEFAULT_EXECUTOR_CONDITION_TOKEN,"=");
        remoteMemory.put(CustomExecutorConstant.DEFAULT_EXECUTOR_CALLER_TYPE,"remote");
        remoteMemory.put(CustomExecutorConstant.DEFAULT_EXECUTOR_CONDITION_VALUE,"#[com.znlh.demo.mybatisdemo.fegin.TestFeginClient.getValue(root.key,root.value)]");
        remoteMemory.put(CustomExecutorConstant.DEFAULT_EXECUTOR_CONTEXT_SUBJECT,new Sample("1","2"));
    }

    /**
     * 操作处理功能实现
     * @return
     */
    public int imitateDataFromMemory(String key,String value){
        return Integer.parseInt(key)*Integer.parseInt(value);
    }

}
